{extend name="common/base" /}
{block name="content"}
<div class="row">
	<div class="col-md-12">
		<div class="card" id="loading_box">
			<div class="card-header">
				<header class="card-title">
					{:__('Proof total')}
				</header>
			</div>
			<div class="card-body">
				<div class="table-responsive">
					<table class="table table-bordered">
						<thead>
							<tr>
								<th colspan="2">{:__('Status')}：
									{if $proof_status }
										<span style="color:green">{:__('Open')}</span><a href="javascript:proofStatus(0);">[{:__('Close')}]</a>
										{else /}
										<span style="color:#2288cc">{:__('Close')}</span><a href="javascript:proofStatus(1)">[{:__('Open')}]</a>
									{/if}
								</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td>/</td>
								<td>{:__('All Total')}</td>
								<td>{:__('Create number')}</td>
								<td>{:__('Delete number')}</td>
								<td>{:__('Edit number')}</td>
								<td>{:__('Move number')}</td>
							</tr>
							<tr>
								<td>{:__('All statistics')}</td>
								<td>{$proofInfo.total.site.total}</td>
								<td>{$proofInfo.total.site.create}</td>
								<td>{$proofInfo.total.site.delete}</td>
								<td>{$proofInfo.total.site.move}</td>
								<td>{$proofInfo.total.site.move}</td>
							</tr>
							<tr>
								<td>{:__('Day total')}</td>
								<td>{$proofInfo.total.day.total}</td>
								<td>{$proofInfo.total.day.create}</td>
								<td>{$proofInfo.total.day.delete}</td>
								<td>{$proofInfo.total.day.move}</td>
								<td>{$proofInfo.total.day.move}</td>
							</tr>
						</tbody>
					</table>
				</div>




				<p style="clear: both;"></p>
				<hr>
				<small class="text-muted">
					<li>{:__('You can edit the unprotected directory name by pressing the [Exclude] button')}</li>
					<li>{:__('You can edit the protected file type through the [Protect] button')}</li>
				</small>
			</div>
		</div>
	</div>
</div>
<div class="row">
	<div class="col-md-6 col-lg-6" id="loading_box1">
		<div class="card card-hover-shadow">
			<header class="card-header">
				<div class="card-title">{:__('Protect file name')} <a href="javascript:inc('protect')" class="btn btn-xs btn-warning">{:__("Add")}</a>
				</div>
			</header>
			<div class="card-body">
				<table class="table table-striped table-borderless">
					<tbody>
						{volist name="proofInfo.protectExt" id="protectExt"}
						<tr>
							<td>{$protectExt}</td>
							<td><a href="javascript:delProof('{$protectExt}','protect')">{:__('Delete')}</a></td>
						</tr>
						{/volist}
					</tbody>
				</table>
			</div>
		</div>
	</div>
	<div class="col-md-6 col-lg-6" id="loading_box2">
		<div class="card card-hover-shadow">
			<header class="card-header">
				<div class="card-title">{:__('Exclude folder')} <a href="javascript:inc('excloud')" class="btn btn-xs btn-warning">{:__("Add")}</a>
				</div>
			</header>
			<div class="card-body">
				<table class="table table-striped table-borderless">
					<tbody>
						{volist name="proofInfo.excludePath" id="excludePath"}
						<tr>
							<td>{$excludePath}</td>
							<td><a href="javascript:delProof('{$excludePath}','excloud')">{:__('Delete')}</a></td>
						</tr>
						{/volist}
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
	function proofStatus(type) {
		var l = $('#loading_box').lyearloading({
			opacity: 0.125,
			spinnerSize: 'lg'
		});
		$.post('{:url("index/vhost/proofStatus")}', {
				lock: type
			}, function (res) {
				EchoMsg(res.msg, 1);
			})
			.fail(function () {
				EchoMsg('{:__("Request error, please try again later")}');
			})
			.always(function () {
				l.destroy();
			})
	}

	function delProof(name, type) {
		id_text = type == 'protect' ? 'loading_box1' : 'loading_box2';
		$.confirm({
			title: '{:__("Reminder")}',
			content: '{:__("Confirm delete?")}',
			icon: 'mdi mdi-alert',
			animation: 'scale',
			closeAnimation: 'zoom',
			buttons: {
				confirm: {
					text: '{:__("Confirm")}',
					btnClass: 'btn-orange',
					action: function () {
						var l = $('#'+id_text).lyearloading({
							opacity: 0.125,
							spinnerSize: 'lg'
						});
						$.post('{:url("index/vhost/delProof")}', {
								name: name,
								type: type
							}, function (res) {
								EchoMsg(res.msg, 1);
							})
							.fail(function () {
								EchoMsg('{:__("Request error, please try again later")}');
							})
							.always(function () {
								l.destroy();
							})
					}
				},
				'{:__("Cancel")}': function () {}
			}
		});
	}

	function incProof(name, type) {
		id_text = type == 'protect' ? 'loading_box1' : 'loading_box2';
		var l = $('#' + id_text).lyearloading({
			opacity: 0.125,
			spinnerSize: 'lg'
		});
		$.post('{:url("index/vhost/incProof")}', {
				name: name,
				type: type
			}, function (res) {
				EchoMsg(res.msg, 1);
			})
			.fail(function () {
				EchoMsg('{:__("Request error, please try again later")}');
			})
			.always(function () {
				l.destroy();
			})
	}

	function inc(type) {
		str = type == 'protect' ? '{:__("Protect")}' : '{:__("Exclude")}';
		str2 = type == 'protect' ? '{:__("File name")}' : '{:__("File dir")}';
		$.confirm({
			title: '{:__("Add")}' + str,
			content: '<div class="form-group p-1 mb-0">' +
				'  <label class="control-label">{:__("Enter to add")}' + str + '{:__(" Content")}</label>' +
				'  <input autofocus="" type="text" id="input-value" placeholder="{:__("Please enter %s","")}' + str2 +
				'" class="form-control">' +
				'</div>',
			buttons: {
				sayMyName: {
					text: '{:__("Submit")}',
					btnClass: 'btn-orange',
					action: function () {
						var input = this.$content.find('input#input-value');
						var errorText = this.$content.find('.text-danger');
						if (!$.trim(input.val())) {
							$.alert({
								content: "{:__('Can not be empty')}。",
								type: 'red'
							});
							return false;
						} else {
							incProof(input.val(), type);
						}
					}
				},
				'{:__("Close")}': function () {}
			}
		});
	}
</script>
{/block}